﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class frmTraCuu : Form
    {
        public frmTraCuu()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        TraCuucrtDTO dto = new TraCuucrtDTO();
        bool temp1;
        bool temp2;
        TraCuuDTO tc = new TraCuuDTO();
        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            if (cbbMaPhong.SelectedItem == null && txtTenPhong.Text == "" && txtTenLoaiPhong.Text == "" && cbbTinhTrang.SelectedItem == null && cbbGiaThapNhat.SelectedItem == null && cbbGiaCaoNhat.SelectedItem == null)
            {
                MessageBox.Show("Vui Long Chon Hay Nhap It Nhat 1 Gia Tri!!!");
            }
            else
            {
                TraCuuBUS bus = new TraCuuBUS();
                List<TraCuuListDTO> ds = new List<TraCuuListDTO>();
                ds = bus.TraCuu(dto,tc);
                dataGridTraCuu.DataSource = ds;
            }
        }
        
        private void cbbMaPhong_SelectedIndexChanged(object sender, EventArgs e)
        {
            dto.MaPhong = true;
            tc.MaPhong = cbbMaPhong.SelectedItem.ToString();
        }

        private void frmTraCuu_Load(object sender, EventArgs e)
        {
            dto.MaPhong = false;
            dto.TenPhong = false;
            dto.TenLoaiPhong = false;
            dto.TinhTrang = false;
            dto.GiaCa = false;
            TraCuuBUS bus = new TraCuuBUS();
            List<string> ds = new List<string>();
            ds = bus.LoadMaPhong();
            for (int i = 0; i < ds.Count; i++)
            {
                cbbMaPhong.Items.Add(ds[i]);
            }
        }

        private void cbbTinhTrang_SelectedIndexChanged(object sender, EventArgs e)
        {
            dto.TinhTrang = true;
            tc.TinhTrang = cbbTinhTrang.SelectedItem.ToString();
        }

        private void cbbGiaThapNhat_SelectedIndexChanged(object sender, EventArgs e)
        {
            temp1 = true;
            if (temp2 == true)
            {
                dto.GiaCa = true;
                tc.GiaThapNhat = int.Parse(cbbGiaThapNhat.SelectedItem.ToString());
                temp1 = false;
            }
        }

        private void cbbGiaCaoNhat_SelectedIndexChanged(object sender, EventArgs e)
        {
            temp2 = true;
            if (temp1 == true)
            {
                dto.GiaCa = true;
                tc.GiaCaoNhat = int.Parse(cbbGiaCaoNhat.SelectedItem.ToString());
                temp2 = false;
            }
        }

        private void txtTenPhong_TextChanged(object sender, EventArgs e)
        {
            if (txtTenPhong.Text != "")
            {
                dto.TenPhong = true;
                tc.TenPhong = txtTenPhong.Text;
            }
        }

        private void txtTenLoaiPhong_TextChanged(object sender, EventArgs e)
        {
            if (txtTenLoaiPhong.Text != "")
            {
                dto.TenLoaiPhong = true;
                tc.TenLoaiPhong = txtTenLoaiPhong.Text;
            }
        }
    }
}
